#include <iostream>
#include <string>
#include <cmath>
using namespace std;
bool is_prime(int num) {
    if (num < 2) {
        return false;
    }
    for (int i = 2; i <= sqrt(num); ++i) {
        if (num % i == 0) {
            return false;
        }
    }
    return true;
}

void closest(string a) {
    string s = "";
    string words[10] = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };

    int c = 0;
    for (int i = 0; i < 3; ++i) {
        int f = a.find(' ', c);
        string word = a.substr(c, f - c);

        int digit = -1;
        for (int j = 0; j < 10; ++j) {
            if (word == words[j]) {
                digit = j;
                break;
            }
        }

        if (digit == -1) {
            cout << "Wrong input" << endl;
            return;
        }

        s += to_string(digit);

        c = f + 1;
    }

    if (s.length() != 3) {
        cout << "Wrong input" << endl;
        return;
    }

    int number = stoi(s);

    int l = number;
    int r = number;
    while (true) {
        if (is_prime(l)) {
            cout << l << endl;
            return;
        }
        if (is_prime(r)) {
            cout << r << endl;
            return;
        }
        l--;
        r++;
    }
}

int main() {
    string text;
    getline(cin, text);

    closest(text);

    return 0;
}
